
package com.compuvest.web;

// <editor-fold defaultstate="collapsed" desc="import">
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.compuvest.ics.ICSAuth;
// </editor-fold>

public class ContextInit implements ServletContextListener {

    private final static Logger log = Logger.getLogger(ContextInit.class.getName());

    ServletContext context;

// <editor-fold defaultstate="collapsed" desc="contextInitialized()">

    @Override
    public void contextInitialized(final ServletContextEvent event) {

        context = event.getServletContext();

        StringBuilder out = new StringBuilder();
        out.append("Init:");

        // maps all session
//        context.setAttribute("context.clientList", clientsList);
//        out.append("\n\tcontext.clientList ... Done");

        // init mysql
        context.setAttribute("sb", new SQLBean());
        out.append("\n\tsb ... Done");

        // init mail
        context.setAttribute("mail", new Mail());
        out.append("\n\tmail ... Done");

        // init ics
        context.setAttribute("ics", new ICSAuth());
        out.append("\n\tics ... Done");

        context.setAttribute("advertShow", new AdvertShow());
        out.append("\n\tadvertShow ... Done");

        log.log(Level.INFO, out.toString());
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="contextDestroyed()">

    @Override
    public void contextDestroyed(ServletContextEvent event) {

	context = event.getServletContext();
//	context.removeAttribute("context.clientList");
	context.removeAttribute("sb");
	context.removeAttribute("mail");
	context.removeAttribute("ics");
	context.removeAttribute("advertShow");

        log.log(Level.INFO, "Destroy");
    }
// </editor-fold>
}
